package com.bto.solar.work.controller;

import com.bto.solar.work.common.R;
import com.bto.solar.work.dao.ILeaseLessorService;
import com.bto.solar.work.dto.LeaseLessorRes;
import com.bto.solar.work.entity.LeaseLessor;
import com.bto.solar.work.service.BtoLeaseLessorService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 承租人 前端控制器
 * </p>
 *
 * @author adrian
 * @since 2023-08-09
 */
@RestController
@RequestMapping("/leaseLessor")
public class LeaseLessorController {

    @Autowired
    private BtoLeaseLessorService leaseLessorService;

    /**
    * 承租人页面展示
    * */
    @GetMapping("/get")
    public R<PageInfo<LeaseLessorRes>> getLeaseLessorList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize){
        PageInfo<LeaseLessorRes> leaseLessorList = leaseLessorService.getLeaseLessorList(pageNum, pageSize);
        return R.ok(leaseLessorList , "承租人数据请求成功");
    }

    /**
     * 新增的下拉框，区域选项
     * http://localhost:6600/area/infos
     * */
    /**
     * 承租人新增
     * */
    @PostMapping("/add")
    public R<String> addLeaseLessor(@RequestBody(required = true) @ApiParam("承租人信息新增") LeaseLessor leaseLessor){
        return leaseLessorService.addLeaseLessor(leaseLessor);
    }

    /**
     * 承租人修改
     * */
    @PutMapping("/update/{id}")
    public R<String> updateLeaseLessor(@RequestBody(required = true) @ApiParam("承租人信息修改") LeaseLessor leaseLessor ,
                                       @PathVariable(value = "id") Integer id){
        return leaseLessorService.updateLeaseLessor(leaseLessor , id);
    }

    /**
     * 承租人删除
     * */
    @DeleteMapping("/delete/{id}")
    public R<String> deleteLeaseLessor(@RequestBody(required = true) @ApiParam("承租人信息删除") @PathVariable(value = "id") Integer id){
        return leaseLessorService.deleteLeaseLessor(id);
    }

}
